package shoppingmall.common.dto;

import lombok.Data;

@Data
public class Result {
    private Integer code;  //响应码:200代表成功，400客户端请求语法错误，401请求未经授权，404请求资源不存在，500服务器错误
    private String msg;  //响应信息，描述字符串
    private Object data;  //返回的数据

    public Result () {
    }
    public Result(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    /**
     * 成功响应
     * @return
     */
    public static Result success () {
        return new Result(200,"success",null);
    }

    public static Result success (Object data) {
        return new Result(200,"success",data);
    }

    /**
     * 失败响应
     * @param msg
     * @return
     */
    public static Result error () {
        return new Result(404, "请求资源不存在!", null);
    }
    public static Result error (String msg) {
        return new Result(400, msg, null);
    }
    public static Result error (Integer code, String msg) {
        return new Result(code, msg,null);
    }
}

